/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javanetworking;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;

/**
 *
 * @author NGUYEN
 */
public class packet implements Serializable{

    private int code;
    private String Filename;
    private String tenchunkmuontai;
    private long offset;
    private byte[] data;
    private int length;

    /**
     * @return the code
     */
    
    
    public packet()
    {
        
    }
    
    public packet(int code, String Filename, String tenchunkmuontai, long offset, byte[] data, int length) {
        this.code = code;
        this.Filename = Filename;
        this.tenchunkmuontai = tenchunkmuontai;
        this.offset = offset;
        this.data = data;
        this.length = length;
    }
    
    public int getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(int code) {
        this.code = code;
    }

    /**
     * @return the Filename
     */
    public String getFilename() {
        return Filename;
    }

    /**
     * @param Filename the Filename to set
     */
    public void setFilename(String Filename) {
        this.Filename = Filename;
    }

    /**
     * @return the tenchunkmuontai
     */
    public String getTenchunkmuontai() {
        return tenchunkmuontai;
    }

    /**
     * @param tenchunkmuontai the tenchunkmuontai to set
     */
    public void setTenchunkmuontai(String tenchunkmuontai) {
        this.tenchunkmuontai = tenchunkmuontai;
    }

    /**
     * @return the offset
     */
    public long getOffset() {
        return offset;
    }

    /**
     * @param offset the offset to set
     */
    public void setOffset(long offset) {
        this.offset = offset;
    }

    /**
     * @return the data
     */
    public byte[] getData() {
        return data;
    }

    /**
     * @param data the data to set
     */
    public void setData(byte[] data) {
        this.data = data;
    }

    /**
     * @return the length
     */
    public int getLength() {
        return length;
    }

    /**
     * @param length the length to set
     */
    public void setLength(int length) {
        this.length = length;
    }
    
    public byte[] toByteArray() {
        ObjectOutputStream ois = null;
        ByteArrayOutputStream baos = null;
        byte[] bytes = null;
        try {
            baos = new ByteArrayOutputStream();
            ois = new ObjectOutputStream(baos);
            ois.writeObject(this);
            bytes = baos.toByteArray();
            baos.close();
            ois.close();
        } catch (Exception e) {
        }
        return bytes;
    }
}
